Utils.searchDialog = {
	options:{
		form:'',
		pagination:'',
		table: {
			element:'',
			columns:[],
			content:'',
		}
	},
	
	install: function(options){
		this.options = $merge(this.options, options);
		
		var form = $(this.options.form);
		
		//pagination
		new Pagination($(this.options.pagination),{
			onPageChange: function(obj){
				form.offset.value = obj.getPageNumber()-1;
				Utils.searchDialog.search_cont(form);
			}
		});
		
		//table header untuk sorting
		new SortableTableHeader($(this.options.table.element).getElement('tr[class:header]'), {
			tableFieldName:this.options.table.columns,
			onHeaderClick:function(item, fieldName, sort){
				form.orderby.value = fieldName+" "+sort;
				Utils.searchDialog.search_cont(form);
			}
		});
		
		Utils.searchDialog.search(form);
	},
	
	search: function(form){
		form.set('send',{
			onSuccess: function(res){
				//table content
				var json = JSON.decode(res);
				$(Utils.searchDialog.options.table.content).set('html', json.table_content);
				
				//rubah jumlah halamannya
				$(Utils.searchDialog.options.pagination).retrieve('pagination').setPageCount(Math.ceil(json.table_num_record/10));
			}
		}).send();
	},
	
	search_cont: function(form){
		form.set('send',{
			onSuccess: function(res){
				//table content
				var json = JSON.decode(res);
				$(Utils.searchDialog.options.table.content).set('html', json.table_content);
			}
		}).send();
	}
}